﻿@model IEnumerable<ExportProfileModel>

@{
    var hasProfiles = Model.Any();
    var isSystemProfiles = (bool)ViewData["IsSystemProfile"];
}

<div class="mb-4">
    <h5 class="text-muted">
		@T(isSystemProfiles ? "Admin.DataExchange.Export.SystemProfilesTitle" : "Admin.DataExchange.Export.UserProfilesTitle")
    </h5>
	<div sm-if="!hasProfiles" class="alert alert-info">
        @T("Admin.DataExchange.Export.NoProfiles")
    </div>
	<div sm-if="hasProfiles && isSystemProfiles" class="alert alert-info">
		@Html.Raw(T("Admin.DataExchange.Export.SystemProfileNote"))
	</div>
    <div sm-if="hasProfiles" class="table-responsive">
		<table class="table admin-table export-profile-list profile-list">
			<thead>
				<tr>
					<th class="text-center"></th>
					<th>@T("Admin.DataExchange.Export.Name")</th>
					<th>@T("Admin.DataExchange.Export.EntityType")</th>
					<th class="text-center">@T("Admin.DataExchange.Export.FileExtension")</th>
					<th class="text-center">@T("Admin.DataExchange.Export.ExportFiles")</th>
					<th>@T("Admin.System.ScheduleTasks.LastStart")</th>
					<th>@T("Admin.System.ScheduleTasks.NextRun")</th>
					<th></th>
				</tr>
			</thead>
			<tbody>
				@foreach (var profile in Model.OrderBy(x => x.Name))
				{
					<tr id="export-profile-@profile.Id" data-profile-id="@profile.Id" data-task-id="@profile.TaskId" class="profile-row" attr-class='(!profile.Enabled, "disabled")'>
						<td class="text-center">
							<img src="@profile.Provider.ThumbnailUrl" alt="@profile.Provider.FriendlyName" attr-class='(profile.Enabled, "o40")' />
						</td>
						<td>
							<a asp-action="Edit" asp-route-id="@profile.Id"><strong>@profile.Name</strong></a>
							<div class="muted">@profile.ProviderSystemName</div>
						</td>
						<td>
							@profile.Provider.EntityTypeName.NaIfEmpty()
						</td>
						<td class="text-center">
							<file-icon file-extension="@profile.Provider.FileExtension" show-label="true" />
						</td>
						<td id="ExportFileCount@(profile.Id)" class="text-center">
							<partial name="ProfileFileCount" model="profile.FileCount" />
						</td>
						<td>
							<div class="last-run-info">
								<partial name="~/Areas/Admin/Views/Scheduling/_LastRun.cshtml" model="profile.TaskModel" />
							</div>
						</td>
						<td class="progress-info">
                            <div class="next-run-info">
								<partial name="~/Areas/Admin/Views/Scheduling/_NextRun.cshtml" model="profile.TaskModel" />
                            </div>
							<div class="task-progress text-muted" 
								attr-class='(!profile.IsTaskRunning, "hide")'
								data-task-id="@profile.TaskId" 
								data-running="@profile.IsTaskRunning.ToString().ToLower()"></div>
						</td>
                        <td class="omega" style="width: 200px;">
                            <button type="button" class="btn btn-block btn-sm btn-warning btn-run-task"
								attr-class='(profile.IsTaskRunning || !profile.Enabled, "hide")'
								data-url="@Url.Action("Execute", "Export", new { area = "Admin", id = profile.Id })"
								data-task-id="@profile.TaskId">
									<i class="fa fa-play"></i>
									<span>@T("Admin.System.ScheduleTasks.RunNow")</span>
                            </button>
                            <a asp-action="CancelJob" asp-controller="Scheduling" asp-route-id="@profile.TaskId" asp-area="Admin"
								class="btn btn-block btn-sm btn-secondary btn-cancel-task confirm"
								attr-class='(!profile.IsTaskRunning, "hide")'
								data-task-id="@profile.TaskId">
									<span>@T("Common.Cancel")</span>
                            </a>
                            <a asp-action="DownloadLogFile" asp-route-id="@profile.Id"
								target="LogFile"
								class="btn btn-block btn-sm btn-secondary btn-log"
								attr-class='(profile.IsTaskRunning || !profile.Enabled || !profile.LogFileExists, "hide")'>
									<i class="far fa-file-alt"></i>
									<span>@T("Admin.Configuration.ActivityLog")</span>
                            </a>
                        </td>
					</tr>
				}
			</tbody>
		</table>
    </div>
</div>
